<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="some-element-you-want-to-animate">
        requestAnimationFrame
    </div>
</body>
<script>
    const element = document.getElementById('some-element-you-want-to-animate');
    let start;

    function step(timestamp) {
        console.log(timestamp)
        if (start === undefined)
            start = timestamp;
        const elapsed = timestamp - start;

        //这里使用`Math.min()`确保元素刚好停在200px的位置。
        element.style.transform = 'translateX(' + Math.min(0.1 * elapsed, 200) + 'px)';

        if (elapsed < 2000) { // 在两秒后停止动画
            window.requestAnimationFrame(step);
        }
    }

    window.requestAnimationFrame(step);
</script>

</html>